package com.ely.coupon.member.controller;

import com.ely.coupon.auth.api.dto.MemberDTO;
import com.ely.coupon.common.core.result.ResponseResult;
import com.ely.coupon.member.api.MemberApi;
import com.ely.coupon.member.dto.MemberInfo;
import com.ely.coupon.member.service.MemberService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 1 认证接口
 * 2 注册接口  (密码需要加密)
 * 3 获取会员信息
 * 4 获取用户收货地址
 * 5 登出接口
 * 6 通过用户名查询会员信息
 * 7 修改会员信息
 * 8 查看领取的优惠卷信息
 * 9 查看用户的订单信息
 */
@RestController
@RequestMapping("/member")
public class MemberController implements MemberApi {
    @Resource
    private MemberService memberService;

    /**
     * 用户认证
     */
    @PostMapping("/auth")
    public ResponseResult<String> auth(String username, String password) {
        return memberService.auth(username, password);
    }

    /**
     * 手机号认证
     */
    @ApiOperation("获取验证码")
    @ApiImplicitParam(name = "phone", value = "手机号")
    @PostMapping("/verify/code")
    public ResponseResult<String> verifyCode(String phone) {
        return ResponseResult.success(memberService.generateVerifyCode(phone));
    }



    @PostMapping("/verify/phone")
    public ResponseResult<String> verifyPhone(String phone, String verifyCode) {
        return ResponseResult.success("");
    }


    @PostMapping("/auth/phone")
    public ResponseResult<String> phoneAuth(String phone, String verifyCode) {
        return ResponseResult.success("");
    }

    @Override
    public ResponseResult<MemberInfo> getMemberInfo(@RequestParam String username) {
        return ResponseResult.success(memberService.getMemberInfo(username));
    }

    @PostMapping("/register")
    public ResponseResult<Integer> register(@RequestBody MemberDTO memberDTO) {
        return ResponseResult.success(memberService.registerMember(memberDTO));
    }


}
